<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <ipt :v="val" @ipt="handleIpt"></ipt>
        <h1>{{val}}</h1>
    </div>
</body>

</html>
<template id="ipt">
    <fieldset>
        <legend>组件</legend>
        <input type="text" :value="v" @input="handleInput">
        <button>点击</button>
    </fieldset>
</template>

<script src='https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js'></script>
<script>
    //v-model如果作用在组件上,要实现双向数据绑定的效果,可以使用父子和子父传参的形式来实现
    Vue.component('ipt', {
        template: "#ipt",
        props: ['v'],
        methods: {
            handleInput(e) {
                // console.log(e.target.value)
                this.$emit('ipt',e.target.value)
            }
        }
    })

    let vm = new Vue({
        el: "#app",
        data: {
            val: "100"
        },
        methods: {
            handleIpt(input) {
                console.log('----',input)
                this.val = input;
            }
        }
    })
</script>